<template>
  <!-- v-loading="true" -->
  <div>
    <pageSearch :searchFormConfig="searchFormConfig" @searchSubmit="searchSubmit" />
    <pageTable :tableData="tableData" :tableInit="params.tableInit" @sizeChange="sizeChange"
      @currentChange="currentChange" @exportFn="exportExcel" v-loading="loading" @pageAdd="openDialog">
      <template #two="{ row }">222 {{ row.two }}</template>
      <template #operation="{ row }">
        <el-button type="primary" link @click="openDrawer">编辑</el-button>
        <el-popconfirm title="确认要删除吗?" @confirm="delData(row.id)">
          <template #reference>
            <el-button type="danger" link>删除</el-button>
          </template>
        </el-popconfirm>
      </template>



    </pageTable>


    <Dialog ref="DialogRef" @submit="DialogSubmit" @onclose="onDialogClose"></Dialog>
    <Drawer ref="DrawerRef" @submit="DrawerSubmit" @onClose="onDrawerClose"></Drawer>




  </div>
</template>

<script setup lang="ts">
import pageSearch from "@/components/base-ui/page-search";
import pageTable from "@/components/base-ui/page-table";
import Dialog from "@/components/base-ui/dialog";
import Drawer from "@/components/base-ui/drawer";



import { searchFormConfig } from "./config/search.config";
import { tableInit } from "./config/table.config";
import { usepageTable } from '@/components/base-ui/page-table/usePageTable'


const getRes = (q) => {
  console.log(q)
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(
        {
          result: [
            {
              date: "1678006429",
              name: "Tom",
              address: "No. 189, Grove St, Los Angeles",
              two: '111'
            },
            {
              date: "1675586074000",
              name: "Tom",
              address: "No. 189, Grove St, Los Angeles",
              two: '111'
            },
            {
              date: "1675586074000",
              name: "Tom",
              address: "No. 189, Grove St, Los Angeles",
              two: '111'
            },
            {
              date: "1675586074000",
              name: "one",
              address: "No. 189, Grove St, Los Angeles",
              two: '111'
            }
          ],
          total: 4
        }
      )
    }, 1000)
  })
}

const {
  exportExcel,
  tableData,
  getData,
  params,
  loading,
  sizeChange,
  currentChange,
  searchSubmit,
  addData,
  DialogRef,
  openDialog,
  DialogSubmit,
  onDialogClose,

  delData,


  DrawerRef,
  openDrawer,
  DrawerSubmit,
  onDrawerClose
} = usepageTable({
  tableInit,
  xlsxName: '某某表格.xlsx',
  getRes,
})

getData()




</script>

<style scoped></style>
